package com.data.core.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.common.pojo.Result;
import com.common.vo.RankingListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.data.core.entry.RankingList;
import com.data.core.service.RankingListService;

import javax.annotation.Resource;

@Api(value = "排行榜相关API")
@RestController
@RequestMapping("ranking")
public class RankingListController {

    @Resource
    private RankingListService rankingListService;

    @ApiOperation(value = "保存排行榜",notes = "保存")
    @PostMapping(value = "save")
    public Result<?> save(@RequestBody RankingListVo rankingListVo) throws Exception {
        Result result = new Result();
        result.OK(rankingListService.save(rankingListVo));
        return result;
    }

    @ApiOperation(value = "更新排行榜",notes = "更新")
    @PostMapping(value = "update")
    public Result<?> update(@RequestBody RankingListVo rankingListVo) throws Exception {
        Result result = new Result();
        result.OK(rankingListService.update(rankingListVo));
        return result;
    }

    @ApiOperation(value = "查询用户排行数据",notes = "查询")
    @PostMapping(value = "find")
    public Result<?> findUserRankingList(@RequestParam Long userId) throws Exception {
        Result result = new Result();
        result.OK(rankingListService.findRankingListByUserId(userId));
        return result;
    }



    @ApiOperation(value = "排行列表",notes = "列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页数", paramType = "query",required = true, dataType = "int"),
            @ApiImplicitParam(name = "pageSize",value = "条数",paramType = "query",required = true,dataType = "int"),
    })
    @PostMapping("page")
    public Result<?> rankingListPage(@RequestBody RankingListVo rankingListVo,
                                  @RequestParam(value = "pageNum") int pageNum,
                                  @RequestParam(value = "pageSize")  int pageSize) throws Exception {
        Result result = new Result();
        Page<RankingList> page = new Page<>(pageNum,pageSize);
        result.OK(rankingListService.rankingListPage(page,rankingListVo));
        return result;
    }

}
